in reply to chmod/chown problem with httpd

You said "delete" in your problem description, but I don't see any call to unlink. Did you mean you have problems renaming the file? Why don't you check the return value of rename and check $! if an error is reported?
if ($linenumber) { rename $logfile, $logfileOrig or die("Can't replace log file: $!\n"); }

Note that $currentline can be replaced with $..