You should check the $depth
argument to make sure the search form only appears at a certain depth/level, e.g. if( 0 === $depth ) { ... }
I personally would place the search form outside the <ul>
though as I don’t think it’s valid HTML. It would hurt your site’s accessibility. Alternatively, wrap it in a <li></li>
so it’s a proper list item.