Fixed the issue of appending to file rather than overwritting