Hi Chris202 and welcome to the monastery.
You can use an open command very similar to the one that already exists in your program, except switching the less-than to a greater-than symbol to indicate output. Then use the Perl select command to indicate that you want print output to go there instead of STDOUT (which is usually the console).
use strict;
use warnings;
open (my $output, '>', 'output.txt') or die "cannot open > output.txt
+$!";
select $output;
open (my $file, '<', 'file.txt') or die "cannot open < file.txt $!";
while (<$file>) {
print unless (/^A/)
}
select *STDOUT;
print "All Done.\n";
The print unless ... idiom in the example above is a more terse way to write the same thing you had in your program.