Running on your terminal session, your script is running as you. Running on IIS, it is (effectively) nobody. Can it from that location reach the other IP, and if so is it authorized to connect to it? The LDAP server console should also be able to tell you more.