Writing to SD card

Hi Guys,
I am trying to build a simple datalogger which has 4 different sensors.
I would also like to log the time between the logging (milis).
Basic idea is to start logging, when a toggle switch is pressed, in a new file after powering everytime.
With my present code, I am successfully able to echo the headers and sensor readings in serial monitor.
But on SD card, it only creates new files (after each power cycle) with only header.

I will be thankful if you guys can suggest what is wrong in the code and why it can't log sensor readings.

Thanks.

Looks like I found the bug.
Thanks anyways,