You should do an atomic move. Otherwise you run the risk of writing out a corrupted file.

1) Create a tmpfile in this directory
2) Write out the new configuration to that file
3) Move tmpfile to s.file.Name()