SD card overwrite

Hello,

For my project I first want to retrieve a word from a file. i want to use this word, make an adjustment on it and then replace the old word with the new word.

I tried this:

SD.open("capacity", FILE_WRITE);
than I get the word out;
SD.close();
SD.remove("capacity) /// removing the file and than make a new empty file with the same name
SD.open("capacity", FILE_WRITE);
SD.write(word);

when I do this and I put the SD card into usb reader, there's an error saying the file is damaged.
How can I overwrite the existing word with the new adjusted word?

thank you !

did you ever close the file after writing the new word?