It keeps you from filling the tank all the way up. It allows an air space for the fuel to expand when it gets hot. If the tank is completely filled to the top, fuel may be expelled from the filler neck when the fuel expands. I believe it is either a federal or EPA requirement. I don't know if the "vent" , as it come to be called, exists on all the VW diesels or only on the ones with the PD motors. I dont think it exists on the gassers. You won't hurt anything by venting the extra air out of the tank, a lot of people are doing it the get the extra range. Somewhere, either here or at tdiclub.com are instructions for removing the vent if you wish. The fuel cap presses this button in when you screw it on, and thus the slight wooshing sound if you didn't vent before hand.
The PD motors run the fuel through the head to get the fuel to the injectors, where it picks up a lot of heat. The excess fuel returns to the tank. I know my Beetle has a fuel cooler under the passenger side area but it don't know if it is cooling the fuel before it goes back to the tank, or before it makes it to the engine. I'll have to look closer at the tubing colors.
P.S. it will also help in future posts to mention the year of your Beetle and any mods in your profile, as there are slight changes over the years. e.g. going from the distributor injection diesel to the PD diesel in 2004.