Can someone please help me to get this piece of code to work... all i get is a 'Wait' displayed when i run it off a server

Code:
#!/usr/bin/perl
$lock_dir = 'Total'; 
$d = mkdir $lock_dir, 0777; 
if ($d == 1 ){
open(FILE,"Total.txt"); 
$oldCount=<FILE>; 
close(FILE); 
open(FILE,">Total.txt"); 
$newCount=$oldCount+1; 
print FILE "$newCount\n"; 
close(FILE);
rmdir $lock_dir; 
 } else {
$newCount = 'Wait';
}
print "Content-type: text/plain\n\n$newCount\n";