Checking for existing title in custom db query not working

use get_page_by_title to get post by title.

I check for it on my system

$post_exist=get_page_by_title( 'Hello world!', ARRAY_A, 'post' );
    if( ! empty( $post_exist ) ) {
          echo 'title exist';
    } else {
        echo 'title not exist';
    }

Running successfully.

In your case it may be like

$title=trim($titles_arr[$i]);
$post_exist=get_page_by_title( $title, ARRAY_A, 'post' );
if( ! empty( $post_exist ) ) {
      echo 'title exist';
} else {
    echo 'title not exist';
}

see also:Get WordPress Post ID from Post title