tl:dr: Your code isn’t running inside WordPress and therefore, $wpdb is not defined. You can fix it by requiring wp-load.php prior to calling your function.
You’re getting this error because you are calling this function from outside of WordPress.
“Call to a member function insert() on a non-object” means that PHP is looking to see if $wpdb is defined as a WordPress Database Access Abstraction Object, but it is not. In fact, the way you have called it, it is basically null.
Therefore, when you set $table_name, it is actually just ‘nd_tempemails’ and when you call $wpdb->insert, PHP can’t do as you request because it has no idea what $wpdb is, other than null.
You can get access to $wpdb from outside WordPress by requiring wp-load.php. See this thread on how you can go about that, and note that how you find the path to wp-load.php depends largely on how your server is set up. That said, generally speaking this will work:
$parse_uri = explode( 'wp-content', $_SERVER['SCRIPT_FILENAME'] );
require_once( $parse_uri[0] . 'wp-load.php' );