I believe you just need to remove these:
- #include
- WiFi.begin(ssid, pass);
I use a Yun Shield on a Mega2560 as well. The Yun Shield connects to my local network and then sends results either to ThingSpeak.com or to a local install of ThingSpeak.
Also, did you put a jumper across the very first pair of pins (directly below from the mounting hole in the board on the top left side) for the ICSP for 16U2 USB interface when the Yun Shield is mounted to the Mega2560? That pair of pins need to be jumpered for the Yun Shield to work with the Mega2560. You will then compile your sketch and save the .hex file to disk, and then log into the Yun Shield and upload that .hex file from the directory where it was placed (same as the location of the .ino file). 2 versions of the .hex file will be created, 1 with a boot loader and 1 without. I use the one without the boot loader and it seems to work okay.
More details can be found here: http://wiki.dragino.com/index.php?title=Yun_Shield#Connect_to_Arduino_Mega2560