You are trying to open the same file twice with the following code...

$ = Open (3, $logfile1, 4)
IF Open(3, $logfile1, 4 ) = 0

just remove the first one and use the "if Open..."

You will need to do this for your other file as well.