pinMode(10,OUTPUT);
You should NOT be diddling with the mode of pin 10 in loop. It MUST be an output pin at all times.
The SD and WiFi libraries should take care of activating the correct slave select pin, so there is no reason for you to be diddling with pin 10 at all. Pin 4, too.
Which WiFi library are you using?