Audio Signal Noise: Understanding & Troubleshooting
The amplifier in the headphones is amplifying the voltage between your head and the cans. This voltage will have lots of mains harmonic pickup from your house wiring. By touching a local voltage reference, you connect (weakly) your head and the amplifier circuit reference voltage, so there is less interfering signal to amplify. It is easy to remove the interfering voltage because its only weakly coupled from the mains in the first place.

There is no safe, easy fix. Earthing yourself is not really a great idea. Better headphones maybe. (they can screen the amplifier, and prevent it picking up spurious signals)