Why are you overriding `write_file`?  https://github.com/rapid7/metasploit-framework/blob/master/lib/msf/core/post/file.rb#L239