I was having the same issue, the script strangely worked on one farm but not on a different farm setup. Different accounts and Web App and sites. Had a close look through each script and in particular the site collections and found out why it kept bombing out on the second farm config.
When creating the site collection DO NOT put a slash at the end of the url. Make the same as the Web App.
Web App url = http://mywebapp.com
Site Collection name = http://mywebapp.com
This resolved this issue for me :-)
When creating the site collection DO NOT put a slash at the end of the url. Make the same as the Web App.
Web App url = http://mywebapp.com
Site Collection name = http://mywebapp.com
This resolved this issue for me :-)