As I’ve already wrote in question comments, at the very beginning of creating the new post or page first choose a template and save as draft. Meta box will appear after save if right template is used.
<?php
add_action( 'add_meta_boxes', 'my_add_meta_box' );
function my_add_meta_box() {
// get template file name
$template_basename = wp_basename( get_page_template() );
// check if right template is used
if('my-template.php' == $template_basename) {
add_meta_box(
'my_metabox',
__('Metabox name'),
'my_display_metabox',
'page',
'normal',
'high'
);
}
}
function my_display_metabox($post) {
wp_nonce_field( 'my_metabox', 'my_metabox_noncename' );
// meta box HTML here
}