moved file deletion to before the fork() to prevent a race condition