prefs: use atomic file writes when saving prefs

(integrated from master branch change cdb7bac by Todd Whiteman <toddw@activestate.com>)