From the example, it looks like you want to merge sort the data, ie get it in the same order, then combine matching rows into something. I suspect
Sort::Merge might be helpful. As others have said, having both files open in parallel is probably a lot faster than re-opening and re-searching eahch, every time.
C.