Put file IO in try except for better error handling