Power loss detection

Maybe you can restructure the way you handle the data.
Write small batches of raw data to the SD card as an when the data is collected. That means at power failure, only a small amount of data is vulnerable to loss.
Periodically, read the raw data from the SD card, convert it to a CSV file and, finally, delete the raw data.