David,

My initial guess:
>   puts "Write histHash[#{i}] = #{histHash[i]}"

replaced with

fileOut.print("#{histHash[i]}\n")

This is what you want?

HTH,
Peter