sudo will only run a program as a different user if one of these 3 conditions has been met (as far as passwords are concerned):
Since options 2 and 3 require a TTY (sudo won't read from a pipe) it won't run if it can't find one. Check your script if at any point you're running a script remotely using ssh, as it's possible that it won't allocate a TTY for a non-interactive remote command.