Changed to use mkdir_p rather than system mkdir -p to allow mocking
Now writes smartosfile