Solution in Ruby with CSV writing