Hardware For Emitting Specific Sound Frequency
Ok, 20KHz is pretty quick with a 1/2 period of 25uS. Code updated to reflect that.

byte outputPin = 2;

void set(){
  pinMode (outputPin, OUTPUT);
}

void loop(){
  while (1){  // added to avoid some of the timing jitter caused by behind the scenes loop() processing
    PIND = 0b00000100; // toggle D2 by writing to the input port
    delayMicroseconds (24); // micro
  }
}


micros() are updated every 64 clock cycles, so 4uS granularity.  If you use anything but 24 or 28, I think it gets rounded up or down to a multiple of 4.  Have to check with an oscilliscope.  The while() code adds a little processing, so 20 or 24 may get you pretty close.

I browsed Digikey and did not see any piezos that did 20 KHz, you may need to use a speaker tweeter to get that range.