in reply to Diff 2 files and print output to file

A typical approach would be to use a hash for such tasks. For example:

(The details may vary slightly depending on whether the same item can occur multiple times in one or both input files...)