Function to check if custom page is used by page?

You can give this a try.

$template_name = get_post_meta( get_the_ID(), '_wp_page_template', true );