SPIFFS how to overwrite a value inside a file

Hi guys i'm aksing for your help because i'm little stuked with this issue:

I'm writing sensors value to a file .csv using SPIFFS memory and a "flag" read == 1 is to read and if read == 0, write the file:

if (read == 1) {
f = SPIFFS.open(file, "r");
} else {
f = SPIFFS.open(file, "a");
}

but I would like to have only ,lets say, 100 value written inside the file and then restart to write the new value from beginning of the file (without delating the file.csv), rewriting line by line each cycle and keeping the "old" value:

when the 100 line is reached, then the new value is stored in line 1 then line 2 , 3 ecc

in this case how i can proceed?

Do you need it done in this exact manor?

It might be easier to initialize your file to have 100 entries (this way you don't need to count ever) and then every time you want to write an entry you delete the first line in the file, then append your line to the end.

This would keep the oldest values first and the newest values last.