i think you could simply do a 

    new Response($contentDocument->getContentAsString(), 200, $contentDocument->getMimeType());

(or however we determine the mime type). no need to go through a temporary file