Periodically, my counter data is deleted. I use the o****er on multiple pages (about 317 of them, to be exact), and every couple of days it reverts to 0 and starts counting again. I have no idea why this happens (not have I activated the "filk lock" function because I don't know what it does).
Any ideas? Here is the main code:

#!/usr/local/bin/perl
#
######################################################################
# Define Variables

# Data file path
my $data_file = "totals.txt";

# Lock file path
my $lock_file = "file.lock";

# Done
###################################

# Do count!
&count_num();

#####################
### Start of subs ###
#####################

##############
sub count_num{
##############
my $count_num;
print "Content-type: text/html", "\n\n";
&file_lock();
unless (open (FILE, "$data_file")){
print "[Sorry! Can't read from the counter data file]\n";
}
$count_num = <FILE>;
chop ($count_num);
close(FILE);
$count_num++;
unless (open (FILE, ">$data_file")){
print "[Can't write to the data file! Counter not incremented!]\n";
}
print FILE "$count_num\n";
close (FILE);
&file_unlock();

1 while $count_num =~ s/(.*\d)(\d\d\d)/$1,$2/;
print "$count_num\n";
}

######################
# File Locking
# Usage: &file_lock();
######################
sub file_lock{
my $i = 1;
while(-e $lock_file){
select(undef,undef,undef,0.1);
if (++$i>60) {
&file_unlock();
}
}
open(FILE,">$lock_file");
close(FILE);
}

########################
# File UnLocking
# Usage: &file_unlock();
########################
sub file_unlock{
unlink($lock_file);
}

#####################
### END OF SCRIPT ###
#####################