writing to file not working