Do multiple smaller file writes instead of one gigantic write.

Calls to write() on MacOS X for more than 2GB fail with EINVAL
instead of successfully writing a smaller number of bytes.