Add flush statement after the search form. Searching can take a long time, this makes sure the search form is output as a whole directly when it's available. With me, the search form will only be output partly as the other half is buffered waiting for search results.