Added check in write to ensure file exists and is writable

Change-Id: I351b9f4c7392b1e924075cd450b1f6ba77db4053