write method updated

updated write method to clear existing contents before writing data.