I'm not sure whether the answer is in the above rather lengthy-looking thread, but it is:

# the die() will never get executed
# because of operator precedence
open my $output , ">$outfile" || die "Can't open the output file!";
# this would work:
open(my $output , ">$outfile") || die "Can't open the output file!";
# and so would this:
open my $output , ">$outfile" or die "Can't open the output file!";