[modutils] ensure file is closed, may cause pb depending on the interpreter (eg pypy). Closes #180876 [applied]