I never had much success with opening an image, using "file.write(line)" and then trying to reopen it. The data gets all screwed up when you do this. You can even do this:
lines = IO.readlines("picture.png")
file = File.open('another_pic.png', 'wb')
lines.each {|line| file.write(line) }
file.close
Now that would appear to simply create another copy of the picture, but it doesn't. I suspect that it has something to do with newlines or special characters or something, I never looked too much into it...
One way I successfully Marshalled an image was a by use of Blizz's Bitmap2Code. I would compress and Marshal the string that created the bitmap, then when you load it just run an "eval" on it. This isn't really saving the actual image to file, obviously, just the method to create it, but I suppose you end up with the same result.
I don't recommend this at all, though, it is horribly inefficient and worthless to actually include any such type of non-sense in a game.