file.replace: replicate ownership/permissions on new file

Since file.replace was changed to use fileinput.input (and perhaps
before this), this function would create a new file with the desired
replacements, and this file would be owned by the user running salt,
with permissions governed by the umask. This is not the expected
behavior. One would expect that the new file would have the same
ownership and permissions as the original file. This commit performs an
os.stat before making changes, and then sets the ownership/permissions
after the changes are made.

Rather than stat-ing the file again after making the changes, since stat
can be an expensive operation, the ownership and permissions are set
irrespective of whether or not they differ from the original state.

Fixes #8399.