to remove a file SD.remove("datalog.txt");
to start with an empty file
File file = FS.open("datalog.txt", O_READ | O_WRITE | O_CREAT);
SD library's FILE_WRITE is O_READ | O_WRITE | O_CREAT | O_APPEN so it would write at the end of the existing file.