get_terms() duplicate first term of a custom taxonomy

I think you want to show list of the category links right?
but you are echo list inside the for-each loop. you have to write that outside of the loop.

foreach ($terms as $term) {
            $term_list .= '<a class="related-market btn btn-outline-secondary" href="' . esc_url(get_term_link($term)) . '">' . $term->name . '</a>';
        }
        echo $term_list;

Also don’t forgot to initialize “$term_list” first in the function.
🙂