If you need send string as file to the client you can do it as follows:

public function sendIcs()
  $icsString = $this->Calendars->generateIcs();
  $response = $this->response;

  // Inject string content into response body
  $response = $response->withStringBody($icsString);

  $response = $response->withType('ics');

  // Optionally force file download
  $response = $response->withDownload('filename_for_download.ics');

  // Return response object to prevent controller from trying to render
  // a view.
  return $response;

In this example you can see how can you send string as iCal file.