in reply to Perl overwriting some lines

If you are expecting that your output file should always have the same number of lines as your input file, then there is something wrong with this part of your second while loop:
while (my $line = <MIC>){ chomp $line; next if exists $preused{$line}; $preused{$line} = 1; ...
If the input file happens to contain any duplicate lines, every non-initial occurrence of a duplicated string will be missing from the output.

Things are added to the "%preused" hash at another point within that loop as well (although I don't really understand how that other part is supposed to work).

You should be looking at the input file to figure out: (a) how many duplicate lines there are, and (b) how many lines might get eliminated due to the conditions that cause other things to be added to %preused.