I'm assuming, based on the errors with == comparison of id1 and id2, that you meant to put newlines in your input files, e.g. for input_at.txt:
and for input_ac.txt:
Like the prior poster, I am also able to get this code to run on my Linux box, though the output is kind of munged. You may want to chomp the line read from FHAC before you split it, then put newlines explicitly where you want them in the output stream. I have seen funky errors with i/o when you don't insert newlines, though the close() call should flush all your streams for you.