Close files to prevent resource leaks