Here is the script:
<?php
$line0PHP = '<?php';
$line1PHP = 'defined( '_JEXEC' ) or die( 'Restricted access' );';
$line2PHP = 'jimport( 'joomla.plugin.plugin');';
$line3PHP = 'jimport( 'joomla.html.parameter');';
$line4PHP = 'class plgSystem'.$titleString.'plugin extends JPlugin';
$line5PHP = '{';
$line6PHP = 'function plgSystem'.$titleString.'plugin()';
$line7PHP = '{';
$line8PHP = '}';
$line9PHP = '}';
$line10PHP = '?>';
$phpFileOutput = $line0PHP.' '.$line1PHP.' '.$line2PHP.' '.$line3PHP.' '.$line4PHP.' '.$line5PHP.' '.$line6PHP.' '.$line7PHP.' '.$line8PHP.' '.$line9PHP.' '.$line10PHP;
$varOutputPhp = print_r($phpFileOutput, true);
file_put_contents($root,$varOutputPhp);
?>
$root
and $titleString
are defined earlier.
You have quoting problems, because you have single quotes inside your single-quoted strings. You need to either escape them, or use double quotes. And you still have a number of HTML entities that need to be replaced with normal characters.
<?php
$line0PHP = '<?php';
$line1PHP = "defined( '_JEXEC' ) or die( 'Restricted access' );";
$line2PHP = "jimport( 'joomla.plugin.plugin');";
$line3PHP = "jimport( 'joomla.html.parameter');";
$line4PHP = 'class plgSystem'.$titleString.'plugin extends JPlugin';
$line5PHP = '{';
$line6PHP = 'function plgSystem'.$titleString.'plugin()';
$line7PHP = '{';
$line8PHP = '}';
$line9PHP = '}';
$line10PHP = '?>';
$phpFileOutput = $line0PHP.' '.$line1PHP.' '.$line2PHP.' '.$line3PHP.' '.$line4PHP.' '.$line5PHP.' '.$line6PHP.' '.$line7PHP.' '.$line8PHP.' '.$line9PHP.' '.$line10PHP;