Instead of:
var parentTxt = $(this).parent('span.folder').text();
use:
var parentTxt = $('span.folder', $(this).closest("ul").parent() ).text();
which basically states:
look for span.folder WITHIN $(this).closest("ul").parent().
If you take a closer look at your markup, it should be clear that when you click on Search, $(this).closest("ul") refers to <ul id="test"> and its parent is the li that contains both, <ul id="test"> AND <span class="folder">.
So essentially this:
$(this).closest("ul").parent()
refers to the first <li> in <ul id="treemenu">. So, to summarize:
$('span.folder', $(this).closest("ul").parent() ).text();
says:
look for span.folder within the li in <ul id="treemenu">
Clear?