My older HP5L used PCL5 and would discern, *.txt/*.pdf/*.ps files using the ljet4 driver from ghostscript. My newer printer uses BR-script3 which is Brothers Postscript compatible driver. On my initial setup, using BR-script3 with lpr would not print pdf's. Using the plxmono would print postscript level 1 and 2 files and PDF <= version 1.4 Postscript printing is usually faster (No pre-processing with ghostscript). The script I linked above essentially looks the first line to see if the file is a pdf or ps. If ID'd as ps, it passes it directly to the printer. The second option, ID'd as pdf, is to convert it to ps using pdf2ps. Lastly, if neither PS or PDF, it assumes a txt file and runs it through enscript.
I wonder if you are not making this overly complex. The handbook has a filter similar to yours in section 9.5.3.4. The only difference is that it utilizes enscript for "pretty" text output and avoids converting a postscript file to PCL
FreeBSD handbook, LinePrinterDaemon