uniq also doesn't deal well with duplicate records that aren't adjacent. You may need to do a sort before using it.
sort | uniq
But that can screw with your header lines, so be careful there two.