The module is not working as expected I can't figure out why this module is not working. What is wrong with it?

/* hook_menu() */
function profilepage_menu() {
  $items['p'] = array(
    'title' =&gt; 'Profile page',
    'page callback' =&gt; 'profile_exe',
    'access callback' =&gt; TRUE,
    'type' =&gt; MENU_CALLBACK,
  );

  return $items;
}

/* Callback function */
function profile_exe($id) { 
  $ar = array('uid' =&gt; $id, 'profilesload' =&gt; profile2_load_by_user($id));

  return theme('profilebuild', array('collected' =&gt; $ar));
}

/* Custom theme function. */
function theme_profilebuild($variables) {
  return "";
}

/* hook_theme() */
function profilebuild_theme() {
  return array(
    'profilebuild' =&gt; array(
      'variables' =&gt; array('profilesload' =&gt; array()),
      'template' =&gt; 'profilepage',
    ),
  );
}


The module is installed and a page called profilepage.tpl.php is in my theme directory AND in the module directory.

The output I'm expecting should be the text in the profilepage.tpl.php page along with the contents of the $variables array which I plan to use in my template.

However, when I open http://example.com/?q=p in my browser, the page loads without errors but the expected content is not there.

What am I doing wrong?
The problem I can see with your code is the file name for the template file that you declare in your hook_theme() implementation.
The file name for the template file should be the theme identifier used as array index in the array returned by hook_theme() (in your case, "profilebuild"); where the identifier uses underscores, the template name should use hyphens.

As example of how the template files are named, see the following hook_theme() implementations for Drupal core modules.

function book_theme() {
  return array(
    'book_navigation' =&gt; array(
      'variables' =&gt; array('book_link' =&gt; NULL), 
      'template' =&gt; 'book-navigation',
    ), 
    'book_export_html' =&gt; array(
      'variables' =&gt; array('title' =&gt; NULL, 'contents' =&gt; NULL, 'depth' =&gt; NULL), 
      'template' =&gt; 'book-export-html',
    ), 
    'book_admin_table' =&gt; array(
      'render element' =&gt; 'form',
    ), 
    'book_title_link' =&gt; array(
      'variables' =&gt; array('link' =&gt; NULL),
    ), 
    'book_all_books_block' =&gt; array(
      'render element' =&gt; 'book_menus', 
      'template' =&gt; 'book-all-books-block',
    ), 
    'book_node_export_html' =&gt; array(
      'variables' =&gt; array('node' =&gt; NULL, 'children' =&gt; NULL), 
      'template' =&gt; 'book-node-export-html',
    ),
  );
}

function aggregator_theme() {
  return array(
    'aggregator_wrapper' =&gt; array(
      'variables' =&gt; array('content' =&gt; NULL), 
      'file' =&gt; 'aggregator.pages.inc', 
      'template' =&gt; 'aggregator-wrapper',
    ), 
    'aggregator_categorize_items' =&gt; array(
      'render element' =&gt; 'form', 
      'file' =&gt; 'aggregator.pages.inc',
    ), 
    'aggregator_feed_source' =&gt; array(
      'variables' =&gt; array('feed' =&gt; NULL), 
      'file' =&gt; 'aggregator.pages.inc', 
      'template' =&gt; 'aggregator-feed-source',
    ), 
    'aggregator_block_item' =&gt; array(
      'variables' =&gt; array('item' =&gt; NULL, 'feed' =&gt; 0),
    ), 
    'aggregator_summary_items' =&gt; array(
      'variables' =&gt; array('summary_items' =&gt; NULL, 'source' =&gt; NULL), 
      'file' =&gt; 'aggregator.pages.inc', 
      'template' =&gt; 'aggregator-summary-items',
    ), 
    'aggregator_summary_item' =&gt; array(
      'variables' =&gt; array('item' =&gt; NULL), 
      'file' =&gt; 'aggregator.pages.inc', 
      'template' =&gt; 'aggregator-summary-item',
    ), 
    'aggregator_item' =&gt; array(
      'variables' =&gt; array('item' =&gt; NULL), 
      'file' =&gt; 'aggregator.pages.inc', 
      'template' =&gt; 'aggregator-item',
    ), 
    'aggregator_page_opml' =&gt; array(
      'variables' =&gt; array('feeds' =&gt; NULL), 
      'file' =&gt; 'aggregator.pages.inc',
    ), 
    'aggregator_page_rss' =&gt; array(
      'variables' =&gt; array('feeds' =&gt; NULL, 'category' =&gt; NULL), 
      'file' =&gt; 'aggregator.pages.inc',
    ),
  );
}


Drupal 7 implementations of that hook is slightly different from the implementation done in Drupal 6, but the "template" index is used in the same way in both the versions.

function block_theme() {
  return array(
    'block_admin_display_form' =&gt; array(
      'template' =&gt; 'block-admin-display-form', 
      'file' =&gt; 'block.admin.inc', 
      'arguments' =&gt; array('form' =&gt; NULL),
    ),
  );
}