conf: don't overwrite a configuration file on serialization error

When a serilization error occurs, the resulting file is empty. We wrap
the file object to write to a temporary file and overwrite the file
only when the whole process has succeeded.

This only works for file-based backend (not directories). YAML is not tested because I didn't find out how to have a serialization error in YAML