No. The safe solution is to write the file with a temporary name into the same directory and then rename it after writing all data to it.
- This way, you will never have an incomplete/truncated file
- If you have an error, the original data will still be intact
- For error handling, you just need to delete the temporary file
It also solves all the problems with backup, source control: You can make them ignore the temp files.