Editted code to write bin number to output file less often