Instead of duplicating the permissions on the temp file, the permissions
are duplicated on the output file directly. If the output file exists as
read-only, it is made writeable first.
There are some environments which don't allow the mv to work if the file
itself is read-only.