Added writeToFolder functionality