You don't have to delete a file to replace it.  If you open it for
"write" (as opposed to "read/write" or "append"), it is automatically
truncated (emptied) and you get only what you write to it.

If you need to open it read/write, you can accomplish the same thing
by explicity truncating it when you're done writing.

But this is not really saving anything in terms of effort over just
creating a new file and moving it into place, which has the distinct
advantage that if something goes awry, you still have the old file to
fall back on.