One thing to note is that the "funky line" has a bug. You're using a hash variable as a reference (the %Bad_Host_Rows->{dirname($row[1])} part. Changing this part to $Bad_Host_Rows{$row[1]} will probably fix your problem.
Recent versions of Perl complain about this problem.