Close files properly in downloads module