boolean - PHP Fatal error: Uncaught Error: Call to a member function saveXML() on bool

one text

We face a error when running the following script.

PHP Fatal error:  Uncaught Error: Call to a member function saveXML() on bool on line 23.

What are we missing here?

<?php 

ini_set('display_errors', 'On');
error_reporting(E_ALL);

$url = "https://urltofeed.com";
$timeout = 1800;

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $timeout);

try {
    $response = curl_exec($curl);
    curl_close($curl);

    // success! Let's parse it and perform whatever action necessary here.
    if ($response !== false) {
        /** @var $xml SimpleXMLElement */
        $xml = simplexml_load_string($response);
        $xml->saveXML("feed.xml");
    } else {
        // Warn the user here
    }
} catch (Exception $ex) {
    // Let user's know that there was a problem
    curl_close($curl);
}

echo 'Download XML done';

?>

Source