Use temp file when writing saveAndRelease() to avoid data loss