There is a command line option -e that you can use to execute and IDL statement at startup. Command line IDL will exit automatically once the command has been executed. Here is a link to the documentation with an example:
http://www.exelisvis.com/docs/Command...
Alternatively, you can use EXIT at the end of your program to force IDL to close once your code has ran. Here is a link ot the documentation regarding EXIT:
http://www.exelisvis.com/docs/EXIT.html