Set term tid programmatically
If you set $term-&gt;tid for a taxonomy term you save with taxonomy_term_save(), the function will take you are updating an existing taxonomy term, with the consequence that the taxonomy term is not saved.

You could change the taxonomy term ID for the taxonomy term you right saved, but there is the risk of conflict with an existing taxonomy term you didn't import. You should change more that one database  table, and you should let other modules handling data related to taxonomy terms know they need to update their data, which means you probably should make those modules think a taxonomy term is deleted, and a new taxonomy term is created.
See also the code for taxonomy_term_delete() to understand what Drupal does when a taxonomy term is deleted.

If you really need to export taxonomy terms from a site, and import them in a different Drupal site, you should be interested to the Universally Unique Identifier module. In that way, the taxonomy term exported from site A, and imported in site B will have the same UUID.
In Drupal 8, any entity defined from Drupal has a UUID. The schema definition used for taxonomy terms in Drupal 8, for example, is the following one.

  $schema['taxonomy_term_data'] = array(
    'description' =&gt; 'Stores term information.', 
    'fields' =&gt; array(
      'tid' =&gt; array(
        'type' =&gt; 'serial', 
        'unsigned' =&gt; TRUE, 
        'not null' =&gt; TRUE, 
        'description' =&gt; 'Primary Key: Unique term ID.',
      ), 
      'uuid' =&gt; array(
        'description' =&gt; 'Unique Key: Universally unique identifier for this entity.', 
        'type' =&gt; 'varchar', 
        'length' =&gt; 128, 
        'not null' =&gt; FALSE,
      ), 
      'vid' =&gt; array(
        'type' =&gt; 'int', 
        'unsigned' =&gt; TRUE, 
        'not null' =&gt; TRUE, 
        'default' =&gt; 0, 
        'description' =&gt; 'The {taxonomy_vocabulary}.vid of the vocabulary to which the term is assigned.',
      ), 
      // …
    ),
    // …
  );