The memory might be running out/getting fragmented when loading and parsing the 2000+ lines script (when imported). Try removing the extra line(s) of code you added, print GC info and see if it is almost running out of memory. You could also try to cross-compile it with mpy-cross, .mpy files use less RAM when loading, if all fails, if you freeze the module in the firmware it should be static and stored in flash and executed in-place.