No worries. As I said, crossposting is fine as long as you let people know.
Regarding your original question again, if it's important that the order of lines of the original file be preserved, I think it's actually better to augment the hash to hold line numbers instead of using an array, as otherwise you'd have to grep through all previous results in each step to make sure you've not already seen a given unique ID (essentially making the whole loop O(n^2) rather than O(n) with regard to the number of lines in your file).
The hash-based solution is easily augmented to accomplish this:
my %results = ();
my $position = 0;
while(...) {
...
if(...) {
$results{$uniqueID} = {
...
'position' => $position++,
...
foreach (sort { $results{$a}->{'position'} <=> $results{$b}->{'positio
+n'} } keys %results) {
...