Check open result before writing in file