system("sort -t\| -2 +3 $OUTPUT_DIR/file.txt > OUTPUT_DIR/file.srt");
Shouldn't this be
system("sort -t\| -2 +3 $OUTPUT_DIR/file.txt > $OUTPUT_DIR/file.srt");
Other than that, I don't see any reason it shouldn't work, unless it's trying to extend your variables beyond their bounds. For example, one time I needed to use ...$var_300... and it assumed my variable wasn't $var but $var_300.
If this happens, this is sort of a hack to get around that.
$tosystem = "sort -t\| -2 +3 " + $OUTPUT_DIR + "/file.txt > " + $OUTPUT_DIR + "/file.srt";