use File.open block to ensure file close