One thing that comes to mind is opening the file once only rather than each time through loop(). The file variable is global so the scope is already ok. I would also probably either write to the file or the Serial port (I assume the latter is for debugging). Serial comms may de disabling interrupts (not sure here...).