Output loop to function return?

First, need to lose query_posts() – it should never be used for secondary loops.

Try something like this:

$posts = get_posts( array(
    'cat' => $category->term_id,
    'numberposts' => 3,
    ));

foreach( $posts as $post ) {

    $listing_code .= get_permalink( $post->ID ); //or whatever
}