create and save data to a file in the files folder from cron
I just need a simple example where a cron hook saves a simple file to a directory inside the files folder.


That would be literally as simple as:

function MYMODULE_cron() {
  $path = 'public://foo/bar/';

  if (file_prepare_directory($path, FILE_CREATE_DIRECTORY)) {
    $content = function_to_generate_content();
    file_put_contents($path . 'baz.ext', $content);
  }
  else {
    // Log an error
  }
}