$line_num is a script variable. It will retain a value only as long as the script that assigned a value to it is being performed. When that script ends, the variable disappears.
If you make it a global variable by naming it $$line_num, the value assigned to the variable will persist until you either change the value with another script step or close the file.
Thanks! It worked perfectly.