You can't mix a header-based redirect with page content. The header is telling the browser to skip displaying a page and go straight to another page.
Since you are using Javascript to display the alert, why not use it to do the redirect too:
<script type="text/javascript">
alert("Wrong Username or Password");
location="page1.php";
</script>