Use temp files for writing keyvault.

Sync now writes a temporary file; if this succeeds, the file is moved to
the actual file. This prevents partial opens (if an Open occurs during a
sync) and helps prevent keyvault corruption during abnormal writes.