Try adding:
@session_start();
above line 33.
When you first view the page it doesn't have the captcha, but then once it fails it doesn't clear? Please be specific when describing the steps to reproduce an issue. That can really help me determine what the cause is.