The code you are trying to run happens when the post is saved, not when the edit page is being displayed. Sequence of actions
1) Submit post
2) Post data is saved
3) Redirect to and reload post edit page
You are attempting to output HTML during an operation that does not product output. I’m surprised that you are not getting PHP errors about headers already sent.