More error resilient handling of .metadata.yaml writes in local storage

Writes updated metadata to a backup file first and then copies it atomically (at least under anything that is not windows where the operation is a bit more complicated and hence not atomic)