in reply to
CGI Script Working fine from my command prompt but Shows Internal server error when called through browser
Did you bother to read (google) the meaning of a 500 error?
Have you read your server log?
Under what ID is the server running your code? (Hint: it's likely not the same ID as when you exectue the code from the command line).
Really important hint: read the instructions around the text entry box! They tell you to wrap your narrative in <p>...(narrative goes here) </p> tags... and your code (so we can read it conveniently) in <code... (code here) </code> tags.