Describe the data handling in more detail.
Take a pair of files AAA.data and BBB.data. After they've been read, will either file ever be part of another pairing? Or is it like a deck of cards in Poker, and after dealing and playing once, the cards are discarded.
If the files are only read once, then I'd open/read/close them once and go on.
Are the paired lines cumulative in some way? That is, do the lines read from the AAA and BBB pairing have any effect on the pairing of files CCC and DDD?
If the effect is cumulative in some way, then you'll need to keep the cumulative data in memory. Unless you're extremely wasteful, I don't see any major obstacles to that. It's going to cost about 20 bytes per line, times 8 million lines, and that's still well under a gigabyte.
If the effect is non-cumulative, then don't accumulate anything. Simply process each pair of files, produce the output, free the memory, and go to the next pair.