in reply to Does die() change the order of execution?

STDOUT is buffered and may appear after STDERR. Put this at the top:
$|++;