This happens because Tempfile is not an IO in MRI, and io.c calls
#to_path on it.  This means MRI reopens the file using a different
handle.

Using #to_io in this case avoids the extra open and writes to the
existing handle:

	IO.copy_stream(StringIO.new('foo'), file.to_io)

But yeah, I wish Tempfile were a subclass of IO in MRI, too...

Keep in mind, blindly calling #to_io isn't a good idea, either, since
some classes (gzip/zlib writer, SSL sockets, etc) only expose #to_io
for IO.select and we never want to write directly to those file handles.