If, for some reason, $USER is not set, you can use the id command to obtain the identity of the real user. So the first time you use the $USER variable, you can use the shell expansion to supply a default value. Change the chown line in your script to:
sudo chown ${USER:=$(/usr/bin/id -run)}:$USER /var/www/$sitename
If USER is empty or unset when this is run, bash will set the USER variable to the output of /usr/bin/id -run