You've trimmed the backtrace a bit too much, so it is hard to say what has gone wrong. If you take the very code example you have, put it in a file and add
void main() { CompileError("C:/EMABE/foo",17,"bar"); }
it will run without errors. At least it did when I tested it, on a windows system.
I however think that your code is overly complex. I would simply use Stdio.write_file().