You are reading a large file into memory. Ruby will have to build an array
to store at least 336,623 lines of text. One line at a time. This takes
time.

The easiest way to make something fast is not to do anything unnecessary.
Like loading the contents of of a file into memory just so you can write
out a fraction of them.