Okay, it is often said, but using warnings and strict forces you to write better code. If you want to debug CGIs use CGI::Carp. And be sure that your webserver/script has the right to alter your counter.dat.
use strict;
use warnings;
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);