file write bug and variable naming

Fixed bug whereby new output files were cumulative, and also cleaned up some intermediate variable naming for clarity.