added try with resource for file write out