I think that I have actually seen this a few times, "BEGIN not safe" with no previous error printed, perhaps when playing with redirections although I don't remember the exact conditions under which this happened. The successful solution has been to first compile the code with the -c option: