Data Logging Stops After Losing GPS Signal

Your code looks wrong to me.

There are two ways to write files on SD cards.

You can open the file once, and keep writing to it.

or

You can open the file, write something to it, and the close it. And the next time you want to write something, open it again. And then close it again.

Both of these methods seem to have reliability issue on the arduino.

But your method seems to be to open the file once, write some stuff, and then close it. And when you get the next gps fix, you try to write more stuff ( without opening the file ), and then close it again. And so on. I am pretty sure that you cannot open the file once and then close it many times, and expect it to work.