It appears that the problem is the security level for Internet Explorer, as I presume you are attempting to run this script on a machine running Windows Server. I have the same issue running this script on Windows Server 2012 and 2016, however when I run it on Windows 10 it works perfectly.
I quickly tried reducing the security level on my Server instance and still had the same issue, so it might be something deeper here but it is definitely OS related.