Put tempfile into binmode before writing
Fall back to Process.gid if we aren't a member of the file's group