Is $_SERVER['QUERY_STRING'] safe from XSS?
You should never trust $_SERVER['QUERY_STRING'] as it can be used for XSS attacks.
In your case, one could exploit the vulnerability with:
http://your.server.com/your_script.php?"><script>alert(111);</script>
Note that the code above works on IE; FireFox and Chrome efficiently encode the query string before sending it to the web server.
I would always wrap it with htmlentities (mind the double_encode parameter) as with every user input.
Good luck!