Ensure files have write permissions when necessary during temp file creation/deletion

- Fixes issue with Perforce source control (files are read-only until checked out)
- Original permissions are restored on original file after temp file deletion