There are a number of ways to do this, more than likely the "right" way of doing this would be to build out the string, then use the Page.ClientScript.RegisterClientScriptBlock method to register the JS, this will put it in the right place
Another alternative, that is more of the quick and dirty way would be to add an control to the page, and rather than response.write, build out the JS, then set the literal control's text property.