you can just overwrite if the new content has the same size or is longer than the previous content.
the SdFat library supports the
truncate() method but the standard builtin SD library does not and you would have to delete and recreate
with the SD library you could explore what you can do with the O_TRUNC mode
- O_TRUNC - If the file exists and is a regular file, and the file is successfully opened and is not read only, its length shall be truncated to 0.
as a way to just replace the content that was there (if that's the intent)
Another approach is to have some data formatting rules, for example you could say that the meaningful data is on the first line - up to the CR/LF mark for example. This way when you overwrite, you insert the end marker and whatever is still in the file after the mark is just to be ignored. (but if security is important you don't want that as previous data might still be left behind).