Twig result/contents into string
You can wrap your HTML in a {% set myString %} block and use myString however you need too. 

{% set myString %}
{% set resultsNum = 0 %}
&lt;h3&gt;{{ block.location }}&lt;/h3&gt;
&lt;ul&gt;
{% set searchString = block.location %}
{% for entry in craft.entries.section('journal').find() %}
{% for block in entry.locations %}
    {% if block.type == "location" %}
    {% if block.location == searchString %}
        {% set resultsNum = resultsNum+1 %}
        &lt;li&gt;&lt;a href="{{ entry.url() }}"&gt;{{ entry.title }}&lt;/a&gt;&lt;/li&gt;
    {% endif %}
{% endif %}
{% endfor %}
{% endfor %}
&lt;/ul&gt;
{% endset %}