How to: Array of field collection items
As per @Andrew comment, instead what you have try printing your HTML start a var outside your foreach and then:

$template .= '&lt;html&gt;';


adding to it, then print it out after your foreach has finished looping. 

In addition make an array outside the foreach, e.g.:

$newarray = array();


Try not using the entity_metadata_wrapper, as it seems like an extra layer of stuff to deal with.