Use title of post as argument for query

Yes! You meant to use get_the_title() which returns the title as a string. the_title instead outputs it to the browser. The same is true of many other functions in WordPress, e.g. the_post_thumbnail vs get_the_post_thumbnail or bloginfo vs get_bloginfo

For future reference, a search on https://developer.wordpress.org will usually reveal related functions