Generating a 20khz sine wave

The PWM output will usually have subharmonics, but a square wave from a digital output will only have regular (higher frequency) harmonics which are not audible at 20kHz. However, non-linearity in your piezo or speaker might create audible subharmonics or resonances.

If you want a true sine wave, you'll need a DAC or audio shield (which has a DAC), or you can filter a square wave, but to filter-out all (or nearly all) of the harmonics, you'd need an active filter.