File Output / Some Stats

Added the file writing sequence. Added a few local variables to keep
track of the stats. Haven't compiled any of it, but looks fine.  Will
polish it all tomorrow.