Replaced open and write with writeFile function which seems to be a bit more seemless when writing content down.