$last_line = $output = system ("~/public_html/cgi-bin/srch.sh &> ~/public_html/errors.txt",$retval);
The above line runs srch.sh and redirects all the output it produces to errors.txt. Therefore, there is no output left to assign to $output (and $last_line). You'll find your last line (together with the rest of the output) in errors.txt.
If not, try running the shell script directly and see if it produces any output at all.