I think you have mistaken the logic in your controller. In case the user is logged in your views are loaded two times. Overwrite your view function with this one:
public function view($page = 'home')
{
$session_data = $this->session->userdata('logged_in');
$data['username'] = $session_data['username'];
$this->load->view('templates/header');
$this->load->view('pages/home');
$this->load->view('templates/footer');
}