ORACLE file I/O withouth explicit flushing on 10g and 11g
According to the documentation for

10g http://docs.oracle.com/cd/B19306_01/appdev.102/b14258/u_file.htm#i1003326

11g http://docs.oracle.com/cd/E11882_01/appdev.112/e40758/u_file.htm#ARPLS70908

and

12c http://docs.oracle.com/cd/E16655_01/appdev.121/e17602/u_file.htm#i1003326


  If there is buffered data yet to be written when FCLOSE runs, then you may receive a WRITE_ERROR exception when closing a file.


So you should call utl_file.fflush(foo); before closing.