Close file and allow Config to be set through a method.

Add defer statement to make sure the file is closed after it has been used.