SD card reliability problem

I have an arduino application that reads sensor data and stores it on the SD card.

I then remove the SD card and put it in the slot on my laptop and copy the files to my laptop and do
further processing of them.

The problem is, about 40% of the time, when I stick the SD card in the laptop, it won't read
the card and wants to re-format the SD card.

It works fine, the other 60% of the time.

I have tried other SD cards and get roughly the same behavior.

Any suggestions how to avoid this happening ?

I'm getting sick of losing data and having to repeat the experiments from scratch.
Could there be a problem with the card being corrupted when the arduino is powered down randomly ?

which sd module do you use?

Could there be a problem with the card being corrupted when the arduino is powered down randomly ?

I don't see why not. There is no "power down" function, so it is very possible the unit would lose power at the end of a write and before close. That I presume would do the most damage.

I would try an experiment.
Put a LED on one pin so you will know when you can shut the power off.
Put a jumper wire on another digital pin.

Leave the jumper pin set to INPUT, but set the pin HIGH. That will turn on the weak pullups. The pin will digitalRead HIGH until you touch the jumper wire to ground. When you want to power down, touch the jumper to ground.

In the loop() check that jumper pin. When it is LOW (touched to ground), turn on the LED, then wait 4 seconds or so, then turn off the LED, wait another second, then do everything else in loop(). Insure during that part of the loop(), the SD is not open.

What do you think?

What do you think?

I think we need to see the code on the Arduino that is possibly corrupting a file on the SD card. When is the file opened? When is it closed? How much data is written between open and close? How long does that take?