Close script file after writing to it.
In Python, the non-empty list is true

… and the empty list is false, so no need to use len().