run a piece of code once in a day in wordpress

Solution:

WordPress has a built-in function/API that just do exactly what you want – doing something every day/hour/any interval you specify.

http://codex.wordpress.org/Function_Reference/wp_schedule_event

Taken shamelessly from the above page

add_action( 'wp', 'prefix_setup_schedule' );
/**
 * On an early action hook, check if the hook is scheduled - if not, schedule it.
 */
function prefix_setup_schedule() {
    if ( ! wp_next_scheduled( 'prefix_daily_event' ) ) {
        wp_schedule_event( time(), 'daily', 'prefix_daily_event');
    }
}


add_action( 'prefix_daily_event', 'prefix_do_this_daily' );
/**
 * On the scheduled action hook, run a function.
 */
function prefix_do_this_daily() {
    // check every user and see if their account is expiring, if yes, send your email.
}

prefix_ is presumably to ensure there will be no collision with other plugins, so I suggest you to change this to something unique.

See http://wp.tutsplus.com/articles/insights-into-wp-cron-an-introduction-to-scheduling-tasks-in-wordpress/ if you want to know more.