When you write to the file, data is not always physically written to the disk, as the disk operation is
buffered (
cached), for the sake of performance. Flushing guarantees that already written part of data is committed to the disk. If your process gets terminated unexpectedly, the already written part of file will be preserved. When you close the file, the data is flushed before closing.
Maybe this explanation is overly simplified, but I think, for writing application, it should be enough to take into account in practical consideration. For more detail, please see:
http://en.wikipedia.org/wiki/Cache_%28computing%29[
^],
http://en.wikipedia.org/wiki/Disk_buffer[
^].
—SA