Form Submission Warning: Cannot modify header error only when plugin is deactivated

You can’t do this:

wp_redirect( get_permalink($pid));

after you’ve already sent content to the browser. Headers were already sent, and wp_redirect is attempting to send a header again. The first three lines of the template you pasted above are all sending content to the browser, when you close and open php. evidently your header.php file is doing the same.

You should hook an action to process your form before the template is loaded.

function wpa63889_process_form( $query ) {
    if ( $query->is_page( 'my-form-page' ) && isset( $_POST['title'] ) ) {
        // process form data
    }
}
add_action( 'pre_get_posts', 'wpa63889_process_form' );