'Also as I said earlier, the script does all the required things when I run it in the command prompt.'
When you run it from the command prompt you are not logged into the server as the IUSR account. The account you are logged on as will (Im sure) have more permissions than the IUSR account. Did you check the IIS settings? Have you read any of the