First, if you have access to $ID, then the initialization has been done and your file is created too late. If you use $ID, then you have to set the global variable:
global $ID;
Without that the file will not be created because $ID doesn't exist. But even if it is created, it will not work as you want, since it will have been created after the initialization sequence. As for Dokuwiki, it has nothing to do with file creation; that is a matter of the interaction between apache and the file system.
Place this code at the top of doku.php:
if(isset($_REQUEST['id'])) {
// <substitute your onw directory for <dokuwiki>
$discussFile = $_SERVER['DOCUMENT_ROOT'].'/<dokuwiki>/data/pages/'.str_replace(':','/',$_REQUEST['id']).'.txt';
if (!file_exists($discussFile))
{
$fh = fopen($discussFile, 'w') or die("can't open file");
$stringData = "~~DISCUSSION~~";
fwrite($fh, $stringData);
fclose($fh);
}
}
Place it before:
require_once(DOKU_INC.'inc/init.php');
It works for me.
___________
Edit
It would be simpler just to use file_put_contents().