Does it help to call $pop->quit() at the end instead of just exit?
In reply to Re: gmail pop3 message deletion bug? by kyle in thread gmail pop3 message deletion bug? by japhy