Try curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); to cause the curl_exec() function to return the data instead of outputting it.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec()