You've already received some excellent advice and I suggest
you use strict and warnings as
little suggests.
Additionally, you might consider creating an END block and
give some diagnostic info:
END {
print "\$n: '$n'\n";
print "\$_: '$_'\n";
close OUT;
## anything else you can think of!
}
--Jim