Fix for #1226. Ensures user has ownership of tempfiles

Two modifications:
 - Use `chown` to `env.user`:`env.user` before calling `chmod`
 - `chmod` now sets permissions 0400 instead of 404, to match the intent of the comment
> # Only root and the user has the right to read the file

(Change to previous request, which was inadvertently based off of `master`)