title: Using File.chown() in ruby as root to be owned by user
body: <p>I'm looking to simply open and write a new file, then have it owned by another user (while running as root). The file creation works alright but the file still ends up being owned by root. I'm using:</p>
  
  <pre><code>doc="text"
  uid=Etc.getpwnam("#{$user}").uid
  
  File.open("#{$file}", 'w') {|f| 
              f.write(doc)
              f.chown($uid,$uid)
      }
  </code></pre>
  
  <p>Any help is greatly appreciated :)</p>