This is because document.write will overwrite the entire DOM if it's called after the document has finished being parsed.
Once I have submitted the form, see the "loading" message, then inspect the DOM using FireBug, I see:
<br><br><font color="#FF6600"><i>Please wait... The ports are being scanned...</i></font>
document.getElementById("my_form") is null.
It would be better to create a <div> element, set the text accordingly, then append it to your form.