You're using wrong the double quotes:
$filters = "library&loc=local,scope:("book")&loc=local,scope:("book2")....";
If you want to use double quotes inside a string declared using double quotes you have to scape them:
$filters = "library&loc=local,scope:(\"book\")&loc=local,scope:(\"book2\")....";
Anyway, the difference between using double and single quotes in php is that double quotes are evaluated, in your case you're not evaluating anything, so you can do this (and is a little faster becouse php doesn't have to evaluate the string)
$filters = 'library&loc=local,scope:("book")&loc=local,scope:("book2")....';
I recommend you to read the php strings documentation to understand the difference between double quoted and single quoted strings and how string evaluation works