How to modify values inside a file
The FILE_WRITE in SD library is 'append' (for historical reasons)

#define FILE_WRITE (O_READ | O_WRITE | O_CREAT | O_APPEND)


so use

 File file = SD.open(filename, O_WRITE);