@jyapayne, I don't mean to be a backseat driver, and I realize you're doing this on the fly in your 'spare' time, but I think your updated code is now duplicating lines (without a newline). For example, I'm seeing close to 400k columns on the final header column that identifies sample IDs (starting at column 10). That's probably why it's going so much slower.
I'm not pointing this out because I want you to write my code, just helping debug since this might wind up in Nim. I should really be doing other things, but I think this may be worth the investment. :-)