Convert `contents` to string before writing to temp file

Fix for edge case in `file.managed` -- if `contents` was parsed as something non-string (say, an int) then it would error when we tried to write it to a temp file.