in reply to Can't find where 500 error is coming from

I'd place  print "Content-type: text/plain\n\n" in the beginning. This way you can see what's happening.

It might be dieing before you can see any output.

update: $datafile should use an absolute filename (  "/dir/file" style).